<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="head-title">
        <title>View Weekly Material Requirement| Merlion's ERP System</title>
    </ui:define>

    <ui:define name="content">
        <p:panel id="panel" header="View Weekly Material Requirement">
            
            <p:ajaxStatus style="width:16px;height:16px;">   
                <f:facet name="start">   
                    <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                </f:facet> 

                <f:facet name="complete">   
                    <h:outputText value="" />   
                </f:facet>   
            </p:ajaxStatus>
            <h:form prependId="false">    
                <p:messages id="messages"/>
                <p:dataTable var="WeeklyMaterialReq" value="#{viewWeeklyRequestFromMRPManagerBean.weeklyMaterialReq}" 
                             id="table" dynamic="true" paginator="true" rows="10" emptyMessage="No Record Yet!" selection="#{viewWeeklyRequestFromMRPManagerBean.selectedWeeklyMaterialReq}" onRowSelectUpdate="display">
                    <p:column selectionMode="single"/>

                    <p:column sortBy="#{WeeklyMaterialReq.id}" filterBy="#{WeeklyMaterialReq.id}"> 
                        <f:facet name="header"> 
                            <h:outputText value="ID" /> 
                        </f:facet> 
                        <h:outputText value="#{WeeklyMaterialReq.id}" /> 
                    </p:column> 

                    <p:column sortBy="#{WeeklyMaterialReq.status}" filterBy="#{WeeklyMaterialReq.status}"> 
                        <f:facet name="header"> 
                            <h:outputText value="Status" /> 
                        </f:facet> 
                        <h:outputText value="#{WeeklyMaterialReq.status}" /> 
                    </p:column>

                    <p:column>
                        <f:facet name="header"> 
                            <h:outputText value="Week" /> 
                        </f:facet> 
                        <h:outputText value="#{viewWeeklyRequestFromMRPManagerBean.getWeekOfYear(WeeklyMaterialReq)}" /> 
                    </p:column>
                    
                    <p:column>
                        <f:facet name="header"> 
                            <h:outputText value="Estimated Processing Week" /> 
                        </f:facet> 
                        <h:outputText value="#{viewWeeklyRequestFromMRPManagerBean.getProcessingWeekOfYear(WeeklyMaterialReq)}" /> 
                    </p:column>
                    
                    <f:facet name="footer">  
                        <p:commandButton value="View" image="ui-icon ui-icon-search" update="display1 display2" oncomplete="ViewDialog.show()"/>
                        <p:commandButton id="convert" value="Convert To Material Request" update="panel table messages" actionListener="#{viewWeeklyRequestFromMRPManagerBean.convertToMaterialRequest(event)}" ajax="true" />
                    </f:facet>

                </p:dataTable>

                <p:dialog header="Weekly Material Requirement Detail" widgetVar="ViewDialog" width="450" height="300" resizable="true" showEffect="clip" hideEffect="fold">
                    <h:panelGrid id="display1" columns="2" cellpadding="5">
                        <h:outputText value="Weekly Material Requirement ID:"/>
                        <h:outputText value="#{viewWeeklyRequestFromMRPManagerBean.selectedWeeklyMaterialReq.id}"/>
                    </h:panelGrid>

                    <p:dataTable var="individualMatReq" value="#{viewWeeklyRequestFromMRPManagerBean.selectedWeeklyMaterialReq.individualMatReqs}" dynamic="true" paginator="true" emptyMessage="No Requirement" id="display2">
                        <p:column sortBy="#{individualMatReq.id}">
                            <f:facet name="header">
                                <h:outputText value="ID"/>
                            </f:facet>
                            <h:outputText value="#{individualMatReq.id}"/>
                        </p:column>

                        <p:column sortBy="#{individualMatReq.rawMaterial.materialType}">
                            <f:facet name="header">
                                <h:outputText value="Ingredient Name"/>
                            </f:facet>
                            <h:outputText value="#{individualMatReq.rawMaterial.materialType}"/>
                        </p:column>
                        
                        <p:column sortBy="#{individualMatReq.totalAmountRequired}">
                            <f:facet name="header">
                                <h:outputText value="Amount Need"/>
                            </f:facet>
                            <h:outputText value="#{individualMatReq.totalAmountRequired}"/>
                        </p:column>
                    </p:dataTable>
                </p:dialog>

            </h:form>
        </p:panel>
    </ui:define>

</ui:composition>